Skip to content

make migrate sync for duable-sqlite #4374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

xlc
Copy link

@xlc xlc commented Apr 7, 2025

there is no reason it needs to be async

with this change, the current example can be updated to:

export class MyDurableObject extends DurableObject {
	storage: DurableObjectStorage;
	db: DrizzleSqliteDODatabase<any>;
	constructor(ctx: DurableObjectState, env: Env) {
		super(ctx, env);
		this.storage = ctx.storage;
		this.db = drizzle(this.storage, { logger: false });
		migrate(this.db, migrations)
	}
	async insertAndList(user: typeof usersTable.$inferInsert) {
		await this.insert(user);
		return this.select();
	}
	async insert(user: typeof usersTable.$inferInsert) {
		await this.db.insert(usersTable).values(user);
	}
	async select() {
		return this.db.select().from(usersTable);
	}
}

however I would also like to suggest updating the example to use the sync methods to avoid async

the fact that current example did not await migrate is also interesting

	async _migrate() {
		migrate(this.db, migrations);
	}

https://orm.drizzle.team/docs/connect-cloudflare-do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant